/**
 * Created by liangpure on 2016/12/20.
 */

import apis from 'server-apis'
import { call, put } from 'redux-saga/effects'
import { takeEvery } from 'redux-saga'
import { FETCH_HOME_LIST, HOME_LIST_SUCCESS, HOME_LIST_FAILED } from './actions'

function getData(url) {
  return fetch(url).then(response => response.json()).then(data => data)
}
function * fetchData() {
  try {
    const data = yield call(getData, apis.GET_HOME_LIST)
    console.log(data.notes)
    yield put({ type: HOME_LIST_SUCCESS, homeList: data.notes })
  } catch (err) {
    yield put({ type: HOME_LIST_FAILED, err })
  }
}
function * watchFetchData() {
  yield* takeEvery(FETCH_HOME_LIST, fetchData)
}
export default watchFetchData
